home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / PROGRAMM / DB_CLIPP / 2510.ZIP / TRSOURCE.EXE / TR_WKDS.PRG < prev    next >
Text File  |  1990-10-22  |  2KB  |  53 lines

  1. *********
  2. * Function : WEEKDAYS
  3. * By : Leonard Zerman
  4. * Placed in the public domain by Tom Rettig Associates, 10/22/1990.
  5. *
  6. * Syntax : WEEKDAYS( <startdate>, <expN days> )
  7. * Returns: <expD> date +- <expN> days
  8. ***********
  9. FUNCTION WEEKDAYS
  10. PARAMETERS tr_startdt, tr_nbr_days
  11. MEMVAR weeks, counter
  12. PRIVATE weeks, counter
  13. IF tr_nbr_days = 0
  14.    RETURN tr_startdt
  15. ENDIF
  16. IF DOW( tr_startdt ) = 1
  17.    IF tr_nbr_days > 0
  18.       tr_startdt  = tr_startdt + 1
  19.       tr_nbr_days = tr_nbr_days - 1
  20.    ELSE
  21.       tr_startdt  = tr_startdt - 2
  22.       tr_nbr_days = tr_nbr_days + 1
  23.    ENDIF
  24. ENDIF
  25. IF DOW( tr_startdt ) = 7
  26.    IF tr_nbr_days > 0
  27.       tr_startdt  = tr_startdt + 2
  28.       tr_nbr_days = tr_nbr_days - 1
  29.    ELSE
  30.       tr_startdt  = tr_startdt - 1
  31.       tr_nbr_days = tr_nbr_days + 1
  32.    ENDIF
  33. ENDIF
  34. IF tr_nbr_days = 0
  35.    RETURN tr_startdt
  36. ENDIF
  37. weeks      = INT( tr_nbr_days / 5 )          && Five work days a week
  38. tr_startdt = tr_startdt + ( weeks * 7 )      && add or sub 7 days a week
  39. counter    = ABS( tr_nbr_days ) - ABS( weeks * 5 )
  40. DO WHILE counter > 0                         && loop though remaining days
  41.    IF tr_nbr_days > 0                        && not decrementing for 
  42.       tr_startdt = tr_startdt + 1            && weekend days 
  43.    ELSE                                      && the day can not land on a
  44.       tr_startdt = tr_startdt - 1            && weekend
  45.    ENDIF                                     && Fri, Sat, Sun, land on Monday
  46.    IF .NOT. ISWKEND( tr_startdt )            && when adding
  47.       counter = counter - 1                  && Mon, Sun, Sat, land on Friday
  48.    ENDIF                                     && when subtracting
  49. ENDDO
  50. RETURN tr_startdt
  51. * eof weekdays *
  52.  
  53.